﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Threading.Tasks;
using OneDrive.Model;
using HtmlAgilityPack;
using System.Text.RegularExpressions;

namespace OneDrive.DataAccess
{
    class SyncAgentInfo
    {
        const string strAjkAgentUrl = "https://xa.anjuke.com/tycoon/p#page/";

        public List<AgentInfo> GetAgentInfoList(int Index)
        {
            List<AgentInfo> agentInfos = new List<AgentInfo>();

            string url = strAjkAgentUrl.Replace("#page", Index.ToString());
            WebClient wc = new WebClient();
            wc.Credentials = CredentialCache.DefaultCredentials;
            Stream resStream = wc.OpenRead(url);
            StreamReader sr = new StreamReader(resStream, System.Text.Encoding.UTF8);
            string strWebContent = sr.ReadToEnd();
            resStream.Close();
            wc.Dispose();


            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(strWebContent);
            string xpathDiv = "//div[@class='jjr-itemmod']";//找到class=jjr-itemmod的div节点
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(xpathDiv);
            foreach (HtmlNode node in nodes)
            {
                AgentInfo agent = new AgentInfo();
                HtmlNode nodeTittle = node.SelectSingleNode(".//div[@class='house-title']");
            }

            return agentInfos;
        }

    }
}
